<?xml version="1.0" encoding="UTF-8"?>
<ui:composition
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
	template="/WEB-INF/templates/business/supplier/template.xhtml">

	<f:metadata>
		<f:viewParam
			name="serviceSupplierId"
			value="#{serviceSupplierHome.id}"></f:viewParam>
		<f:event
			listener="#{serviceSupplierHome.initConversation()}"
			type="preRenderView"></f:event>
		<f:viewParam
			name="moduleName"
			value="中介用户管理"></f:viewParam>
	</f:metadata>
	<ui:define name="supplier_head">

		<style type="text/css">
.column1 {
	width: 20%;
}

.column2 {
	width: 80%;
}

.top-alignment {
	vertical-align: top;
}

.removeButton {
	float: right;
	margin-right: 20px;
}

td {
	padding-bottom: 10px;
}

label {
	font-weight: bold;
}

.photoItem {
	float: left;
}
</style>
	</ui:define>
	<ui:define name="supplier_content">

		<h:form id="editForm">
			<p:messages
				id="messages"
				closable="true">
				<p:autoUpdate />
			</p:messages>
			<p:panel
				id="licenseInfo"
				header="修改待审信息"
				style="margin-bottom:10px">
				<h:panelGrid
					columns="2"
					cellpadding="5"
					columnClasses="column1,column2">

					<p:outputLabel
						for="registeredFund"
						value="注册资金(万元)" />
					<p:inputText
						id="registeredFund"
						value="#{serviceSupplierHome.instance.registeredFund}"
						required="true"
						styleClass="input-small" />

					<p:outputLabel
						for="registrationAuthority"
						value="注册登记机关" />
					<p:inputText
						id="registrationAuthority"
						value="#{serviceSupplierHome.instance.registrationAuthority}"
						required="true"
						styleClass="input-large" />

					<p:outputLabel
						for="registrationNo"
						value="注册登记号" />
					<p:inputText
						id="registrationNo"
						value="#{serviceSupplierHome.instance.registrationNo}" />

					<p:outputLabel
						for="regtime"
						value="成立时间" />
					<p:calendar
						id="regtime"
						value="#{serviceSupplierHome.instance.regtime}"
						required="true"
						pattern="yyyy-MM-dd"
						navigator="true"
						locale="zh_CN"
						inputStyleClass="input-small"
						showOn="button" />
					<p:outputLabel
							for="region"
							value="中介机构所在地区"
					/>
					<p:selectOneMenu id="region"
									 value="#{serviceSupplierHome.instance.region}"
									 required="true">
						<f:selectItem itemLabel="请选择" itemValue="#{null}"  />
						<f:selectItems value="#{codeDicUtils.getCodeDicList('所在地区')}" var="_codeDic" itemValue="#{_codeDic.codeValue}"
									   itemLabel="#{_codeDic.codeName}" />
					</p:selectOneMenu>
					<p:outputPanel>
						<p:outputLabel
							for="businessLicenseImageUpload"
							value="营业执照" />
						<br />
							（扫描图片上传）
						</p:outputPanel>
					<p:outputPanel>
						<p:fileUpload
							id="businessLicenseImageUpload"
							mode="advanced"
							required="true"
							skinSimple="true"
							fileLimit="1"
							invalidSizeMessage="必须上传一张图片，大小不能超过3M!"
							allowTypes="/(\.|\/)(jpe?g|png)$/"
							sizeLimit="#{1024 * 1024 * 3}"
							uploadLabel="上传"
							cancelLabel="取消"
							update="editForm:businessLicenseImage"
							fileUploadListener="#{serviceSupplierHome.uploadBusinessLicenseImage}"></p:fileUpload>
						<p:panel id="businessLicenseImage">
							<p:outputLabel
								rendered="#{serviceSupplierHome.instance.businessLicenseImages.size() > 0}">
								<div id="imgsPreview">
									<img
										data-original="#{attachmentUtils.getFullPath(serviceSupplierHome.instance.businessLicenseImages[0])}"
										src="#{attachmentUtils.getFullPath(serviceSupplierHome.instance.businessLicenseImages[0])}"
										id="img"
										width="240" />
									<p:commandLink
										styleClass="closeBtn"
										action="#{serviceSupplierHome.removeBussinessImage()}"
										update="editForm:businessLicenseImage"
										immediate="true"></p:commandLink>
								</div>

							</p:outputLabel>
						</p:panel>
					</p:outputPanel>
					<ui:remove>
						<p:outputPanel>
							<p:outputLabel
								for="taxProveImagesUpload"
								value="纳税证明" />
							<br />
								（扫描图片上传）
							</p:outputPanel>
						<p:outputPanel>
							<p:fileUpload
								id="taxProveImagesUpload"
								label="选择"
								mode="advanced"
								multiple="true"
								skinSimple="true"
								sizeLimit="#{1024 * 1024 * 3}"
								uploadLabel="上传"
								cancelLabel="取消"
								update="editForm:taxProveImageList"
								fileUploadListener="#{serviceSupplierHome.uploadTaxProveImages}"
								allowTypes="/(\.|\/)(jpe?g|png)$/" />
							<p:panel
								id="taxProveImageList"
								widgetVar="taxProveImageList">
								<p:dataList
									value="#{serviceSupplierHome.instance.taxProveImages}"
									var="_taxImage"
									rendered="#{serviceSupplierHome.instance.taxProveImages.size() > 0}"
									itemStyleClass="photoItem"
									varStatus="_certPhotoStatus">
									<img
										data-original="#{attachmentUtils.getFullPath(_taxImage)}"
										src="#{attachmentUtils.getFullPath(_taxImage)}"
										id="img"
										width="240" />

									<p:commandLink
										styleClass="closeBtn"
										action="#{serviceSupplierHome.removeTaxImage(_taxImage)}"
										update="editForm:taxProveImageList"
										immediate="true"></p:commandLink>
								</p:dataList>
								<div style="clear: both" />
							</p:panel>
						</p:outputPanel>
					</ui:remove>

					<p:outputLabel
						for="alwaysValid"
						value="营业期限" />
					<p:selectOneRadio
						id="alwaysValid"
						value="#{serviceSupplierHome.instance.alwaysValid}"
						required="true">
						<f:selectItem
							itemLabel="填写营业期限"
							itemValue="false" />
						<f:selectItem
							itemLabel="长期有效"
							itemValue="true" />
					</p:selectOneRadio>



					<p:outputLabel
						for="busnissAllotedTime"
						value="输入期限" />
					<p:calendar
						id="busnissAllotedTime"
						value="#{serviceSupplierHome.instance.busnissAllotedTime}"
						pattern="yyyy-MM-dd"
						navigator="true"
						inputStyleClass="input-small"
						showOn="button" />
				</h:panelGrid>
			</p:panel>

			<p:remoteCommand
				name="updateBussinessPanel"
				immediate="true"
				update="businesses"></p:remoteCommand>
			<p:panel
				id="businesses"
				header="主营业务"
				widgetVar="businesses"
				style="margin-bottom:10px;"
				styleClass="nureg-cont nuregcbox nuregcboxsty">
				<c:forEach
					items="#{serviceSupplierHome.instance.mainBusinesses}"
					var="_business"
					varStatus="_status">
					<div class="certs">

						<p:commandLink
							styleClass="removeButton"
							rendered="#{_status.index > 0}"
							immediate="true"
							action="#{serviceSupplierHome.removeBusiness()}"
							ajax="true"
							oncomplete="updateBussinessPanel()">
							<f:setPropertyActionListener
								value="#{_business}"
								target="#{serviceSupplierHome.currentBusiness}"></f:setPropertyActionListener>
							<f:setPropertyActionListener
								value="#{_business.bussinessIndex}"
								target="#{serviceSupplierHome.currentBusinessIndex}"></f:setPropertyActionListener>
						</p:commandLink>
						<h2>主营业务#{_status.index + 1}</h2>

						<h:panelGrid
							columns="2"
							cellpadding="5">
							<p:outputLabel
								for="agentServiceDetail#{_business.bussinessIndex}"
								value="服务事项" />
							<p:outputPanel>
								<p:inputText
									id="agentServiceDetail#{_business.bussinessIndex}"
									widgetVar="agentServiceDetail#{_business.bussinessIndex}"
									value="#{_business.agentService.name}"
									required="true"
									readonly="true"
									styleClass="input-xlarge" />
								<p:commandButton
									oncomplete="PF('chooseAgentServiceDialog').show();"
									value="选择"
									immediate="true"
									update="chooseAgentServiceDialog">
									<f:setPropertyActionListener
										value="#{_business}"
										target="#{serviceSupplierHome.currentBusiness}"></f:setPropertyActionListener>
									<f:setPropertyActionListener
										value="#{_business.bussinessIndex}"
										target="#{serviceSupplierHome.currentBusinessIndex}"></f:setPropertyActionListener>
								</p:commandButton>

							</p:outputPanel>

							<p:outputLabel
								for="commitOfTime#{_business.bussinessIndex}"
								value="服务时限承诺" />
							<p:inputText
								id="commitOfTime#{_business.bussinessIndex}"
								value="#{_business.commitOfTime}"
								required="true"
								styleClass="input-xlarge" />

							<p:outputLabel
								for="commitOfPrice#{_business.bussinessIndex}"
								value="服务收费承诺" />
							<p:inputText
								id="commitOfPrice#{_business.bussinessIndex}"
								value="#{_business.commitOfPrice}"
								required="true"
								styleClass="input-xlarge" />

							<p:outputLabel
								for="commitOfQuality#{_business.bussinessIndex}"
								value="服务质量承诺" />
							<p:inputText
								id="commitOfQuality#{_business.bussinessIndex}"
								value="#{_business.commitOfQuality}"
								required="true"
								styleClass="input-xlarge" />
						
						</h:panelGrid>
								
						<p:panel>
							<p:outputLabel for="uploadImages#{_business.bussinessIndex}" value="请选择图片"></p:outputLabel>
							<p:fileUpload
								id="uploadImages#{_business.bussinessIndex}"
								mode="advanced"
								multiple="true"
								sequential="true"
								
								skinSimple="true"
								allowTypes="/(\.|\/)(jpe?g|png)$/"
								invalidFileMessage="文件类型错误，请上传png或jpg格式的图片"
								sizeLimit="#{1024 * 1024 * 3}"
								invalidSizeMessage="文件大小不能超过3M!"
								uploadLabel="上传"
								cancelLabel="取消"
								update="editForm:uploadedImages#{_business.bussinessIndex}"
								fileUploadListener="#{serviceSupplierHome.uploadAgentServicePhotos}"></p:fileUpload>					
							
							<p:dataTable id="uploadedImages#{_business.bussinessIndex}" value="#{_business.images}" var="_attr" rowIndexVar="_row" emptyMessage="无已上传图片">
							
								<p:column headerText="文件名">
									<h:outputText value="#{_attr.filename}" />
								</p:column>
													
								<p:column headerText="大小（MB）" style="text-align: right;">
									<h:outputText value="#{_attr.filesize / 1024 / 1024}">	
										<f:convertNumber minFractionDigits="2" groupingUsed="true" />
									</h:outputText>
								</p:column>
								
								<p:column headerText="预览">
									<img data-original="#{attachmentUtils.getFullPath( _attr )}" src="#{attachmentUtils.getFullPath( _attr )}" width="240"/>
								</p:column>
								
								<p:column headerText="操作">						
									<p:commandLink styleClass="closeBtn" action="#{serviceSupplierHome.removeAgentServicePhoto(_status.index, _attr)}"  update="editForm:uploadedImages#{_business.bussinessIndex}" immediate="true" ></p:commandLink>
								</p:column>
								
							</p:dataTable>
						</p:panel>
					</div>
				</c:forEach>

				<p:commandButton
					action="#{serviceSupplierHome.instance.addEmptyBusiness()}"
					update="businesses"
					value="添加业务"
					immediate="true"></p:commandButton>
			</p:panel>

			<p:commandButton
				id="submitBtn"
				action="#{serviceSupplierHome.reSubmitBussinessLicense()}"
				value="保存"
				ajax="true">
				<p:tooltip
					id="toolTipGrow1"
					for="submitBtn"
					value="请谨慎重新提交审核,在审核期间，会影响您的选取！"
					showEffect="clip"
					hideEffect="explode"
					position="bottom" />
			</p:commandButton>

		</h:form>

		<p:dialog
			id="infoTip"
			visible="true"
			closable="false"
			showEffect="true"
			widgetVar="infoTip"
			width="666"
			height="300"
			modal="true">
			<h:form>
				<p:panel>
					<f:facet name="header">提示信息</f:facet>
					<p:panel>
						<font style="font-size: 16px; color: red; padding: 10px">
							修改此页面的信息,需要管理员重新审核，在信息审核期间，会影响您的选取，请谨慎修改！ </font>

					</p:panel>

					<f:facet name="footer">
						<p:commandButton
							value="确定修改"
							onclick="PF('infoTip').hide();" />
						<p:button
							value="取消修改"
							outcome="unitInfo.xhtml" />
					</f:facet>
				</p:panel>
			</h:form>
		</p:dialog>

		<p:dialog
			id="chooseAgentServiceDialog"
			widgetVar="chooseAgentServiceDialog"
			width="666"
			height="600"
			modal="true">
			<h:form>
				<p:panel>
					<f:facet name="header">选择服务事项</f:facet>

					<p:scrollPanel
						style="height: 450px; border: 0px;"
						mode="native">
						<p:dataTable
							var="_service"
							value="#{agentServiceList.resultList}"
							rows="10"
							paginator="true"
							paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
							rowsPerPageTemplate="5,10,15"
							selection="#{serviceSupplierHome.selectedAgentServiceMap[serviceSupplierHome.currentBusinessIndex]}"
							rowKey="#{_service.name}">
							<p:column
								selectionMode="single"
								style="width:16px;text-align:center" />
							<p:column headerText="服务事项名称">
								<h:outputText value="#{_service.name}" />
							</p:column>
							<p:column headerText="对应资质大类">
								<h:outputText value="#{_service.qualificationClass.name}" />
							</p:column>
						</p:dataTable>
					</p:scrollPanel>

					<f:facet name="footer">
						<p:commandButton
							value="确定"
							action="#{serviceSupplierHome.updateAgentService()}"
							update="editForm:agentServiceDetail#{serviceSupplierHome.currentBusinessIndex}"
							oncomplete="PF('chooseAgentServiceDialog').hide();" />
						<p:commandButton
							value="取消"
							onclick="PF('chooseAgentServiceDialog').hide();" />
					</f:facet>
				</p:panel>
			</h:form>
		</p:dialog>
	</ui:define>

</ui:composition>
